package com.tzstcl.sys.user.ctrl;

import com.tzstcl.base.model.AjaxResult;
import com.tzstcl.commons.utils.StringUtils;
import com.tzstcl.commons.utils.UploadFileUtil;
import com.tzstcl.framework.shiro.ShiroUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @BelongsProject: xt5
 * @BelongsPackage: com.tzstcl.xt5.org.ctrl
 * @Author: guohy
 * @CreateTime: 2019-03-08 15:17
 * @Description: 图片上传控制器
 * @Version: 1.0
 */
@Controller
public class UploadCtrl {
    @RequestMapping("/uploadFile")
    @ResponseBody
    public AjaxResult upload(MultipartFile uploadFile) throws IOException {
        String fileName = uploadFile.getOriginalFilename();
        String type="image";
//        if(StringUtils.isNotBlank(ShiroUtils.getOrgId())){
//            type+=  ShiroUtils.getOrgId();
//        }
        Map<String, Object> respData  = UploadFileUtil.saveFile(uploadFile, type);
        respData.put("fileName", fileName);
        return AjaxResult.success("success", respData);
    }
}
